/*
 * Copyright (C) 拾光分享网
 * All rights reserved, Designed By www.hiai.top.
 * Email：goodsking@163.com.
 */
package top.hiai.download;

import com.jfinal.plugin.activerecord.Db;
import top.hiai.common.model.Article;
import top.hiai.common.model.Download;

/**
 * @Author www.hiai.top
 * @Email goodsking@163.com
 * @Message 更多资源尽在www.hiai.top
 * @Introduction 类的介绍
 */

public class DownloadService {

    private Article articleDao = new Article().dao();
    private Download download = new Download().dao();

    /**
     * 判断用户是否下载过文章资源了
     *
     * @param uid
     * @param aid
     * @return
     */
    public Article getCountByUserIdAndArticleId(int uid, int aid) {
        return articleDao.findFirst("select * from bbs_download where user_id=? and article_id=?", uid, aid);
    }

    /**
     * 根据文章的ID获取文章的信息，用户修改文章
     *
     * @param aid
     * @return
     */
    public Article findById(int aid) {
        return articleDao.findById(aid);
    }

    /**
     * 扣除下载人的积分
     *
     * @param uid
     * @param articlePoints
     */
    public void setUserReducePoints(int uid, int articlePoints) {
        Db.update("update bbs_user set points=? where uid=?", articlePoints, uid);
    }

    /**
     * 给上传文章的用户加上相应的积分
     *
     * @param uid
     * @param articlePoints
     */
    public int setUserAddPoints(int uidArticle, int articlePoints) {
        return Db.update("update bbs_user set points=points+'" + articlePoints + "' where uid='" + uidArticle + "'");
    }
}